<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div{
        display: inline-block;
        width: 200px;
        height: 210px;
        border: 1px #e6e6e6 solid;
      }
      #text{
        vertical-align: top;
      }
    </style>
  </head>
  <body>
    <div>
      Bootstrap是基于HTML.css.javaScript开发的简洁,直观,强悍的前端开发框架,使web开发跟家快捷
      能制作响应式网页. bootstrap自适应:
      Bootstrap根据屏幕大小吧设备分为超小屏幕,小屏幕,中等屏幕,大屏幕四种并把屏幕分为12列
      对应屏幕宽度为:
    </div>  
    <textarea name="fuzhi" id="text" cols="70" rows="10"></textarea>
    <button id="btn">一键复制</button>
    <script>
      const btn = document.getElementById("btn");
      const div = document.querySelector('div')
      const text = document.getElementById('text')
      btn.addEventListener("click", function() {
        const value = div.innerHTML
        const textarea = document.createElement('textarea')
        textarea.style.position = 'absolute'
        textarea.style.left = '-9999px'
        textarea.value = value
        document.body.appendChild(textarea)
        // 将textarea中的文本选中
        textarea.select()
        // 将选中的文本复制并且返回true给result
        const result = document.execCommand('Copy')
        if(result){
          alert('复制成功')
        }
      });
    </script>
  </body>
</html>
